package policy;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-07
 * Time: 23:32
 */

//演示拒绝策略.DiscardOldestPolicy： 抛弃队列中等待最久的任务 然后把当前任务加入队列中。
public class MyThreadPoolDemo6 {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(
                1,
                2,
                2,
                TimeUnit.HOURS,
                new ArrayBlockingQueue<>(1),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );
        //根据参数线程最多有15个，这里测试有16个任务
        for(int i=1;i<=10;i++) {
           int y=i;
           threadPoolExecutor.submit(()->{
               System.out.println(Thread.currentThread().getName()+"---"+y);
           });
        }
        threadPoolExecutor.shutdown();
    }
    
}
